/*
 * Copyright (c) 2009, DanikX Corporation. All Rights Reserved.
 */

package kz.home.parser;

import java.util.Vector;

/**
 * <strong>title</strong>
 * <p> describe
 *
 * @author: Danik <br>
 * Date: 08.07.2009  <br>
 * Time: 16:06:29  <br>
 */
public class Parser {
    protected Vector table = new Vector();
    protected String source;
    protected final String DATA = "DATA";


    public void add(String source) {
        this.source = source;
    }

    public Vector parse() {
        int i = 0;
        while (i < source.length() - 1) {
            if (source.charAt(i) == '\n') {
                String temp = source.substring(0, i).trim();
                if (addOrNotToList(temp)) table.addElement(temp);
                //
                source = source.substring(i + 1, source.length());
                i = 0;
                continue;
            }
            i++;
        }
        //printList();
        table.addElement("roms[0]=\"\"");
        return table;
    }

    protected boolean addOrNotToList(String source) {
        boolean contain = (source.startsWith("var dates")
                || source.startsWith("roms[")
                || source.startsWith("cits[")
                || source.startsWith("cins[")
                || source.startsWith("movs[")
                || source.startsWith("tims[")
        );

        boolean notContain = !(contains(source, "which")
                || contains(source, "temp")
                || contains(source, "[i]")
        );

        return contain && notContain;
    }

    private boolean contains(String source, String value) {
        return source.indexOf(value) != -1;
    }
}
